package br.com.ss.utilserver;

import java.text.MessageFormat;
import java.util.ResourceBundle;

import br.com.ss.enumeration.EMensageError;

public class Message {
	
	private static ResourceBundle bundle;
	private static ResourceBundle bundleErro;

	
    public static String getMessage(String key, Object[] params){
        
        if(bundle == null){
                bundle = ResourceBundle.getBundle("br.com.ss.messagebundle.base");
        }       
        
        String value = bundle.getString(key);
        
        if(params != null){
        	MessageFormat formatter = new MessageFormat(value, bundle.getLocale());
            value = formatter.format(params);
        }
        
        
        return value;
    }
    
    public static String getMessageErro(String key, Object[] params)
    {
        if(bundleErro == null)
        {
        	bundleErro = ResourceBundle.getBundle("br.com.ss.messagebundle.erro");
        }       
        
        String value = bundleErro.getString(key);
        
        if(params != null)
        {
        	MessageFormat formatter = new MessageFormat(value, bundleErro.getLocale());
            value = formatter.format(params);
        }
        
        return value;
    }
    
    public static String getMessageErro(EMensageError erroMsgType, Object[] params)
    {
    	return getMessageErro(erroMsgType.getCodigo(), params);
    }    
}